using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;

public class FeatureMono : MonoBehaviour
{
    public Pawn Pawn;

    public void Init(Pawn pawn)
    {
        Pawn = pawn;
    }

    public List<Feature> Features = new List<Feature>();

    public bool IfHasFeature(Type FeatureType)
    {
        foreach (var feature in Features)
        {
            if (feature.GetType() == FeatureType)
            {
                return true;
            }
        }
        return false;
    }

    public void InitFeaturesByCard(Card card)
    {
        Features.Clear();
        foreach (var feature in card.Features)
        {
            var newFeature = Instantiate(feature);
            Features.Add(newFeature);
            newFeature.Reset();
        }
    }

    /// <summary>
    /// 调用这个 初始挂载的feature对委托进行注册
    /// </summary>
    public void InitFeatures()
    {
        foreach (var feature in Features)
        {
            feature.Init(Pawn);
        }
    }

    public void RemoveFeatures()
    {
        foreach (var feature in Features)
        {
            feature.Remove(Pawn);
        }
    }
    public void RemoveFeature(Type type)
    {
        Feature removed = null;
        foreach (var feature in Features)
        {
            if(feature.GetType() == type)
                removed = feature;
        }
        if(removed != null)
        {
            Features.Remove(removed);
        }
    }

    public void IniteFeature(Feature feature)
    {
        feature.Init(Pawn);
    }

    public void AddNewFeatureByRoots(Roots roots)
    {
        foreach (var feature in roots.RootsFeatures)
        {
            var newFeature = Instantiate(feature);
            newFeature.originalRoots = roots;
            Features.Add(newFeature);
            if (feature.IfForever)
            {
                Pawn.Card.Features.Add(newFeature);
                Debug.Log("特效");
            }
        }
    }
}
